package com.education.user.service;


import com.education.user.mapper.SysUserMsgMapper;
import com.education.user.pojo.SysUserMsg;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.List;

@Service
public class SysUserMsgService {

    @Autowired
    private SysUserMsgMapper sysUserMsgMapper;

    //根据消息id查询消息
    public List<SysUserMsg> findByMsgIdAndUserId(Integer userId, Integer msgId){
        SysUserMsg sysUserMsg = new SysUserMsg();
        sysUserMsg.setUserId(userId);
        sysUserMsg.setMsgId(msgId);
        return sysUserMsgMapper.select(sysUserMsg);
    }

    /**
     * 查询消息信息
     * @param msgId
     * @return
     */
    public List<SysUserMsg> findByIsRead(Integer msgId) {
        SysUserMsg sysUserMsg = new SysUserMsg();
        sysUserMsg.setMsgId(msgId);
        List<SysUserMsg> select = sysUserMsgMapper.select(sysUserMsg);
        return select;
    }

    /**
     * 查询已读消息
     */
    public List<Integer> selectAll(){
        List<Integer> list = new ArrayList<>();
        List<SysUserMsg> sysUserMsgs = sysUserMsgMapper.selectAll();
        for (SysUserMsg sysUserMsg : sysUserMsgs) {
            list.add(sysUserMsg.getMsgId());
        }
        return list;
    }

    //添加消息
    public Integer insert(SysUserMsg sysUserMsg){
        return sysUserMsgMapper.insert(sysUserMsg);
    }


    public List<SysUserMsg> select(SysUserMsg sysUserMsg){
        return sysUserMsgMapper.select(sysUserMsg);
    }
}
